#ifndef SERVER_H
#define SERVER_H

#include <QObject>
#include <QDebug>
#include <QHttpServer>
#include <QWebSocketServer>
#include <QProtobufSerializer>

////////////////////////////////////
/// HTTP 服务器
////////////////////////////////////
class HttpServer : public QObject
{
    Q_OBJECT
private:
    static HttpServer *instance;
    HttpServer();

    QHttpServer _httpServer;
    QProtobufSerializer _serializer;

public:
    static HttpServer *getInstance();

    bool init();

    QHttpServerResponse getUserInfo(const QHttpServerRequest &req);
    QHttpServerResponse getFriendList(const QHttpServerRequest &req);
    QHttpServerResponse getChatSessionList(const QHttpServerRequest &req);
    QHttpServerResponse getApplyList(const QHttpServerRequest &req);
    QHttpServerResponse getRecentMsg(const QHttpServerRequest &req);
    QHttpServerResponse newMsg(const QHttpServerRequest &req);
    QHttpServerResponse setNickname(const QHttpServerRequest &req);
};

////////////////////////////////////
/// WebSocket 服务器
////////////////////////////////////
class WebSocketServer : public QObject
{
    Q_OBJECT
private:
    static WebSocketServer *instance;
    WebSocketServer();

    QWebSocketServer _webSocketServer;

    QProtobufSerializer _serializer;

    int _messageIndex = 0;

public:
    static WebSocketServer *getInstance();

    bool init();
signals:
    void sendText();
};

#endif // SERVER_H
